﻿using BW.MesProject.Production.Domain;
using BW.MesProject.Production.Domain.Dto.Input;
using BW.MesProject.Production.Domain.Dto.Input.WorkOrder;
using BW.MesProject.Production.Domain.Model;
using BW.MesProject.Production.Infrastructure;
using BW.MesProject.Public.ErrorCode;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;

namespace BW.MesProject.Production.Host.Controllers
{
    /// <summary>
    /// 工单控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class WorkOrderController : ControllerBase
    {
        private readonly IWorkOrderServices _workOrderServices;
        public WorkOrderController(IWorkOrderServices workOrderServices)
        {
            _workOrderServices = workOrderServices;
        }
        /// <summary>
        /// 添加工单信息
        /// </summary>
        /// <param name="workorder"></param>
        /// <returns></returns>
        [HttpPost]
        public ApiResult<int> CreateWorkOrder(AddWorkOrderInput input)
        {
            return _workOrderServices.CreateWorkOrder(input);
        }
        /// <summary>
        /// 删除工单信息
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpDelete]
        public ApiResult<int> DeleteWorkOrder(int Id)
        {
            return _workOrderServices.DeleteWorkOrder(Id);
        }
        /// <summary>
        /// 获取工单信息
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpGet]
        public ApiResult<WORKORDERMODEL> GetWorkOrder([FromQuery]int Id)
        {
            return _workOrderServices.GetWorkOrder(Id);
        }
        /// <summary>
        /// 获取工单列表
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpGet]
        public ApiResult<List<WORKORDERMODEL>> GetWorkOrders([FromQuery]PageInput input)
        {
            return _workOrderServices.GetWorkOrders(input);
        }
        /// <summary>
        /// 修改工单信息
        /// </summary>
        /// <param name="workorder"></param>
        /// <returns></returns>
        [HttpPut]
        public ApiResult<int> UpdateWorkOrder(UpdateWorkorderInput workorder)
        {
            return _workOrderServices.UpdateWorkOrder(workorder);
        }
        /// <summary>
        /// 工单拆分
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public ApiResult<int> SplitWorkOrder(SplitWorkOrderInput input)
        {
            return _workOrderServices.SplitWorkOrder(input);
        }
        /// <summary>
        /// 获取下发工单
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpGet]
        public ApiResult<List<WORKORDERMODEL>> GetStartWorkOrders([FromQuery]PageInput input)
        {
            return _workOrderServices.GetStartWorkOrders(input);
        }
        /// <summary>
        /// 下发工单
        /// </summary>
        /// <param name="WorkOrderCode"></param>
        /// <returns></returns>
        [HttpPost]
        public ApiResult<int> StartWorkOrder(string WorkOrderCode)
        {
            return _workOrderServices.StartWorkOrder(WorkOrderCode);
        }
    }
}
